package com.zyh.controller;

import com.github.pagehelper.PageInfo;
import com.zyh.entity.Pet;
import com.zyh.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pet")
public class PetController {
    @Autowired
    PetService service;

    @PostMapping("/")
    public void insert(@RequestBody Pet pet){
        service.insert(pet);
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") Integer id){
        service.deleteById(id);
    }

    @DeleteMapping("/")
    public void deleteMany(@RequestBody int[] ids){
        service.deleteMany(ids);
    }

    @PutMapping("/")
    public void update(@RequestBody Pet pet){
        service.update(pet);
    }

    @GetMapping("/{id}")
    public Pet selectById(@PathVariable("id") Integer id){
        return service.selectById(id);
    }

    @GetMapping("/")
    public List<Pet> selectAll(){
        return service.selectAll();
    }

    @GetMapping("/{pageNum}/{pageSize}")
    public PageInfo<Pet> selectByPage(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
        return service.selectByPage(pageNum, pageSize);
    }
}
